﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using StateMachine;

namespace LilTmSim
{
	public class TransitionNodeCollection : ObservableCollection<TransitionNode>
	{
		public delegate void CollectionAndNode(TransitionNodeCollection sender, TransitionNode node);
		public event CollectionAndNode OnItemInserted;
		public event CollectionAndNode OnItemRemoved;

		protected override void InsertItem(int index, TransitionNode item)
		{
			if (OnItemInserted != null)
				OnItemInserted(this, item);
			base.InsertItem(index, item);
		}

		protected override void RemoveItem(int index)
		{
			if (OnItemInserted != null)
				OnItemRemoved(this, this[index]);
			base.RemoveItem(index);
		}

		public IEnumerable<Transition> TransitionDataList
		{
			get
			{
				return this.OfType<TransitionNode>().Select(t => t.TransitionData);
			}
		}
	}
}
